import { Body, Controller, Get, HttpCode, Post, Query, Delete, UseGuards } from '@nestjs/common';
import { TestService } from './test.service';
import { log } from 'console';
import { AddRoleDto } from './dto/addRoleDto';
import { EditRoleDto } from './dto/editRoleDto'
import { RoleEntity } from './entity/role.entity';
import { SingleIdDto } from 'src/store/dto/SingleIdDto';
import { AuthGuard } from 'src/auth/guard/auth.guard';
import { BodyDto } from 'src/store/vo/BodyDto';

@Controller('/test')
// @UseGuards(AuthGuard)
export class TestController {

  // 注入 Service
  constructor(private readonly testService: TestService) { }

  /**
   * 新增
   * @param addRoleDto 角色数据
   * @returns true or false
   */
  @Post('addRole')
  @HttpCode(200)
  async addRole(@Body() addRoleDto: AddRoleDto): Promise<BodyDto<Boolean>> {
    log('add-body', addRoleDto)

    return this.testService.addRole(addRoleDto)
  }

  /**
   * 查询
   * @param id 角色ID
   * @returns 角色信息
   */
  @Get('getRole')
  getRole(@Query() { id }: SingleIdDto): Promise<BodyDto<RoleEntity | null>> {
    log('get-query', id)

    return this.testService.getRole(id)
  }

  /**
   * 编辑
   * @param editRoleDto 数据信息
   * @returns true or false 
   */
  @Post('editRole')
  @HttpCode(200)
  editRole(@Body() editRoleDto: EditRoleDto): Promise<BodyDto<Boolean>> {
    log('edit-body', editRoleDto)

    return this.testService.editRole(editRoleDto)
  }

  /**
   * 删除
   * @param id 角色ID
   * @returns true or false
   */
  @Delete('deteleRole')
  deleteRole(@Query() { id }: SingleIdDto): Promise<BodyDto<Boolean>> {
    log('detele-query', id)

    return this.testService.deleteRole(id)
  }
}
